add utility function gdk_quartz_fix_cap_not_last_line() which fixes the
authorMichael Natterer <mitch@imendio.com>
Thu, 7 Jun 2007 22:26:27 +0000 (22:26 +0000)
committerMichael Natterer <mitch@src.gnome.org>
Thu, 7 Jun 2007 22:26:27 +0000 (22:26 +0000)
2007-06-08  Michael Natterer  <mitch@imendio.com>

* gdk/quartz/gdkdrawable-quartz.c: add utility function
gdk_quartz_fix_cap_not_last_line() which fixes the coordinates for
GDK_CAP_NOT_LAST lines at least for horizontal and vertical lines.

(gdk_quartz_draw_segments)
(gdk_quartz_draw_lines): use it here.

svn path=/trunk/; revision=18080

ChangeLog
gdk/quartz/gdkdrawable-quartz.c

index 1e2f5ef94946b65b9a3dab01a6a18e87d0988d6f..2d52f33ea48731b3deafffabf0673c8f5295318a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2007-06-08  Michael Natterer  <mitch@imendio.com>
+
+       * gdk/quartz/gdkdrawable-quartz.c: add utility function
+       gdk_quartz_fix_cap_not_last_line() which fixes the coordinates for
+       GDK_CAP_NOT_LAST lines at least for horizontal and vertical lines.
+
+       (gdk_quartz_draw_segments)
+       (gdk_quartz_draw_lines): use it here.
+
 2007-06-07  Michael Natterer  <mitch@imendio.com>
 
        * gdk/quartz/gdkgc-quartz.c: add gdk_gc_quartz_init() and set
index 113bee4d674a3913aac40abe74f586f9f3f5d5bf..30ac9097821833c48f5502ec492334e6344b5abd 100644 (file)
@@ -366,6 +366,33 @@ gdk_quartz_draw_points (GdkDrawable *drawable,
   gdk_quartz_drawable_release_context (drawable, context);
 }
 
+static inline void
+gdk_quartz_fix_cap_not_last_line (GdkGCQuartz *private,
+                                 gint         x1,
+                                 gint         y1,
+                                 gint         x2,
+                                 gint         y2,
+                                 gint        *xfix,
+                                 gint        *yfix)
+{
+  *xfix = 0;
+  *yfix = 0;
+
+  if (private->cap_style == GDK_CAP_NOT_LAST && private->line_width == 0)
+    {
+      /* fix only vertical and horizontal lines for now */
+
+      if (y1 == y2 && x1 != x2)
+       {
+         *xfix = (x1 < x2) ? -1 : 1;
+       }
+      else if (x1 == x2 && y1 != y2)
+       {
+         *yfix = (y1 < y2) ? -1 : 1;
+       }
+    }
+}
+
 static void
 gdk_quartz_draw_segments (GdkDrawable    *drawable,
                          GdkGC          *gc,
@@ -373,18 +400,28 @@ gdk_quartz_draw_segments (GdkDrawable    *drawable,
                          gint            nsegs)
 {
   CGContextRef context = gdk_quartz_drawable_get_context (drawable, FALSE);
+  GdkGCQuartz *private;
   int i;
 
   if (!context)
     return;
 
+  private = GDK_GC_QUARTZ (gc);
+
   _gdk_quartz_gc_update_cg_context (gc, drawable, context,
                                    GDK_QUARTZ_CONTEXT_STROKE);
 
   for (i = 0; i < nsegs; i++)
     {
+      gint xfix, yfix;
+
+      gdk_quartz_fix_cap_not_last_line (private,
+                                       segs[i].x1, segs[i].y1,
+                                       segs[i].x2, segs[i].y2,
+                                       &xfix, &yfix);
+
       CGContextMoveToPoint (context, segs[i].x1 + 0.5, segs[i].y1 + 0.5);
-      CGContextAddLineToPoint (context, segs[i].x2 + 0.5, segs[i].y2 + 0.5);
+      CGContextAddLineToPoint (context, segs[i].x2 + 0.5 + xfix, segs[i].y2 + 0.5 + yfix);
     }
   
   CGContextStrokePath (context);
@@ -399,19 +436,32 @@ gdk_quartz_draw_lines (GdkDrawable *drawable,
                       gint         npoints)
 {
   CGContextRef context = gdk_quartz_drawable_get_context (drawable, FALSE);
-  int i;
+  GdkGCQuartz *private;
+  gint xfix, yfix;
+  gint i;
 
   if (!context)
     return;
 
+  private = GDK_GC_QUARTZ (gc);
+
   _gdk_quartz_gc_update_cg_context (gc, drawable, context,
-                                    GDK_QUARTZ_CONTEXT_STROKE);
+                                   GDK_QUARTZ_CONTEXT_STROKE);
 
   CGContextMoveToPoint (context, points[0].x + 0.5, points[0].y + 0.5);
 
-  for (i = 1; i < npoints; i++)
+  for (i = 1; i < npoints - 1; i++)
     CGContextAddLineToPoint (context, points[i].x + 0.5, points[i].y + 0.5);
 
+  gdk_quartz_fix_cap_not_last_line (private,
+                                   points[npoints - 2].x, points[npoints - 2].y,
+                                   points[npoints - 1].x, points[npoints - 1].y,
+                                   &xfix, &yfix);
+
+  CGContextAddLineToPoint (context,
+                          points[npoints - 1].x + 0.5 + xfix,
+                          points[npoints - 1].y + 0.5 + yfix);
+
   CGContextStrokePath (context);
 
   gdk_quartz_drawable_release_context (drawable, context);